<template>
	<!-- 生活缴费 -->
	<view>
		<!-- <view class="nav">
			<uni-nav-bar :border="false" left-icon="left" leftText="返回" rightText="缴费记录" title="生活缴费" />
		</view>
		 -->
		<view class="area">
			<view class="address">
					<picker @change="bindPickerChange" :value="index" range-key="building" :range="list">
				<view>{{model.building}}</view>
				</picker>
				<view class="iconfont icon-xiabiao icons"></view>
				
			</view>
			
			<view class="fee">
				<view class="title">应缴费:{{sumFice}}元</view>
				<view class="btn">
					缴费
				</view>
			</view>
		</view>
		
		<view class="bill" v-for="item in freeList" :key="item.id">
			<view class="bill_li">
				<view>物业账单</view>
			</view>
			<view class="bill_li border">
				<view>房号</view>
				<view>{{item.houseno}}</view>
			</view>
			<view class="bill_li border">
				<view>账单</view>
				<view>{{item.begindate}} 至 {{item.enddate}}</view>
			</view>
			<view class="bill_li border">
				<view>账单金额</view>
				<view>￥{{item.price}}元</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {getMyHouses} from '../../api/house.js'
	import {getFeeList} from '../../api/fee.js'
	export default {
		data() {
			return {
				index:0,
				model:{houseid:0,building:""},
				list:[],
				params:{houseid:0,state:0,page:1,psize:100000},
				freeList:[]
			}
		},
		onLoad() {
			this.getHouse();
		},
		computed:{
			sumFice(){
				
				let sum= this.freeList.reduce((pre,item)=>pre+item.price,0);
			    
				 sum=(Math.round(sum*100)/100).toFixed(2);
				 return  Number(sum);
				
			}
		},
		methods: {
			bindPickerChange(e){
			 console.log(e);	
			},
		  async	getFree(){
			  
			  const res=await getFeeList(this.params);
			  if(res.errCode===10000){
				  this.freeList=res.data.list;
				  
				  console.log(999,this.freeList);
			  }
				
			},
			async getHouse(){
				const res=await getMyHouses();
				if(res.errCode===10000){
					this.list=res.data.list.map(item=>({houseid:item.houseid,building:item.building+item.houseno}));
					console.log(123,this.list);
					
					if(this.list.length>0){
						this.model=this.list[0];
						this.params.houseid=this.model.houseid;
					}
					this.getFree();
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
@import url('@/static/css/livefee.css');
</style>
